package com.ist.word.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.JobAttributes;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import com.ist.word.audio.AudioPlayer;
import com.ist.word.logic.GameConfigurations;

public class GameMenuList extends JFrame implements ActionListener {


	private ImageButton NewGameButton, ResumeGameButton, OptionButton,
			ExitButton;
	Image backgroundImage = Toolkit.getDefaultToolkit().getImage(
			this.getClass().getResource(
					GameConfigurations.GAMEMENULIST_BACKGROUND));
	private JPanel MenuListPanel;
	static private final Dimension mainFrameSize = new Dimension(
			GameConfigurations.GAMEMENULIST_WIDTH,
			GameConfigurations.GAMEMENULIST_HEIGHT);
	private final JComponent backgroundCanvas = new JComponent() {
		protected void paintComponent(Graphics g) {
			super.paintComponent(g);
			Graphics gg = g.create();
			gg.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this);
			gg.dispose();
		}
	};
	private int newGameFlag=0;
	private int continueGameFlag=0;
	private AudioPlayer buttonAudioPlayer;
	
	public int getNewGameFlag() {
		return newGameFlag;
	}
	
	public void setNewGameFlag(int newGameFlag) {
		this.newGameFlag = newGameFlag;
	}
	
	public int getContinueGameFlag() {
		return continueGameFlag;
	}

	public void setContinueGameFlag(int continueGameFlag) {
		this.continueGameFlag = continueGameFlag;
	}

	public Dimension getPreferredSize() {
		return mainFrameSize;
	}

	public Dimension getMaximumSize() {
		return mainFrameSize;
	}

	public Dimension getMinimumSize() {
		return mainFrameSize;
	}

	public Dimension getSize() {
		return mainFrameSize;
	}

	public void doLay() {
		Container container = getContentPane();
		container.add(backgroundCanvas);
		container.setSize(getWidth(), getHeight());
		pack();
		setVisible(true);
	}

	public void init() {
		NewGameButton = new ImageButton();
		NewGameButton.setLocation(65, 180);
		NewGameButton.setSize(180, 40);
		NewGameButton.addActionListener(this);
		NewGameButton.setImage(GameConfigurations.GAMEMENU_NEWGAME_NORMALICON);
		NewGameButton.setPressedImage(GameConfigurations.GAMEMENU_NEWGAME_HIGHLIGHTICON);
		NewGameButton.setRolloverImage(GameConfigurations.GAMEMENU_NEWGAME_HIGHLIGHTICON);
		
		ResumeGameButton = new ImageButton();
		ResumeGameButton.setLocation(65, 250);
		ResumeGameButton.setSize(180, 40);
		ResumeGameButton.addActionListener(this);
		ResumeGameButton.setImage(GameConfigurations.GAMEMENU_RESUMEGAME_NORMALEICON);
		ResumeGameButton.setPressedImage(GameConfigurations.GAMEMENU_RESUMEGAME_HIGHLIGHTICON);
		ResumeGameButton.setRolloverImage(GameConfigurations.GAMEMENU_RESUMEGAME_HIGHLIGHTICON);

		OptionButton = new ImageButton();
		OptionButton.setLocation(65, 315);
		OptionButton.setSize(180, 40);
		OptionButton.addActionListener(this);
		OptionButton.setImage(GameConfigurations.GAMEMENU_OPTION_NORMALICON);
		OptionButton.setPressedImage(GameConfigurations.GAMEMENU_OPTION_HIGHLIGHTICON);
		OptionButton.setRolloverImage(GameConfigurations.GAMEMENU_OPTION_HIGHLIGHTICON);

		ExitButton = new ImageButton();
		ExitButton.setLocation(65, 380);
		ExitButton.setSize(180, 40);
		ExitButton.addActionListener(this);
		ExitButton.setImage(GameConfigurations.GAMEMENU_EXIT_NORMALICON);
		ExitButton.setPressedImage(GameConfigurations.GAMEMENU_EXIT_HIGHLIGHTICON);
		ExitButton.setRolloverImage(GameConfigurations.GAMEMENU_EXIT_HIGHLIGHTICON);

		MenuListPanel = new JPanel();
		MenuListPanel.setLayout(null);
		MenuListPanel.setOpaque(false);
		MenuListPanel.add(NewGameButton);
		MenuListPanel.add(ResumeGameButton);
		MenuListPanel.add(OptionButton);
		MenuListPanel.add(ExitButton);
		
		
		this.setTitle("Refactor");
		this.setIconImage(Toolkit.getDefaultToolkit().createImage(
				this.getClass().getResource(GameConfigurations.GAMETITLE_BARICON)));
		this.setLayout(new BorderLayout());
		this.add(MenuListPanel, BorderLayout.CENTER);
		this.setSize(mainFrameSize);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
		this.setResizable(false);
		this.setLocationRelativeTo(null);

	}

	public GameMenuList() {
		super();
		//init();
		
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		GameMenuList gameMenuList=new GameMenuList();
		gameMenuList.init();
		gameMenuList.doLay();
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		if (NewGameButton == arg0.getSource()) {
			newGameFlag=1;
			//System.out.println("newGameFlag click");
			buttonAudioPlayer=new AudioPlayer(GameConfigurations.GAMEBUTTON_MUSIC);
			buttonAudioPlayer.play();
		}
		if (ResumeGameButton == arg0.getSource()) {
			continueGameFlag=1;
			//System.out.println("continueGameFlag click");
			buttonAudioPlayer=new AudioPlayer(GameConfigurations.GAMEBUTTON_MUSIC);
			buttonAudioPlayer.play();
		}
		if (OptionButton == arg0.getSource()) {
			buttonAudioPlayer=new AudioPlayer(GameConfigurations.GAMEBUTTON_MUSIC);
			buttonAudioPlayer.play();
			JOptionPane.showMessageDialog(null, "Innovations Supprise Tomorrow®");
		}
		if (ExitButton == arg0.getSource()) {
			buttonAudioPlayer=new AudioPlayer(GameConfigurations.GAMEBUTTON_MUSIC);
			buttonAudioPlayer.play();
			System.exit(NORMAL);
		}

	}

}
